package com.huidian.resource.server.controller;

import com.huidian.resource.client.MeterFeign;
import com.huidian.resource.client.dto.MeterDto;
import com.huidian.resource.server.entity.Meter;
import com.huidian.resource.server.service.IMeterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author super on 2021-04-03 11:18:17
 * Copyright (c) huidiancloud
 */
@RestController
@Slf4j
public class MeterCtrl implements MeterFeign {

	@Resource
    private IMeterService meterService;

    @Override
    public List<MeterDto> selectList(@RequestBody MeterDto meterDto) {
        Meter meter = new Meter();
        BeanUtils.copyProperties(meterDto,meter);
        List<Meter> meterList = meterService.selectList(meter);
        List<MeterDto> meterDtoList = new ArrayList<>(meterList.size());
        MeterDto dto;
        for (Meter m: meterList) {
            dto = new MeterDto();
            BeanUtils.copyProperties(m,dto);
            meterDtoList.add(dto);
        }
        return meterDtoList;
    }


    @Override
    public MeterDto selectById(@RequestParam("meterId") Long meterId) {
        Meter meter = new Meter();
        meter.setMeterId(meterId);
        Meter meter1  = meterService.selectOne(meter);

        MeterDto meterDto = new MeterDto();
        BeanUtils.copyProperties(meter1,meterDto);

        return meterDto;
    }

	
}
